package com.zigong.app.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.zigong.app.R;
import com.zigong.app.beans.NewsItem;
import com.zigong.app.ui.utils.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/17 0017.
 */

public class CityStaNewsHolder extends BaseRecylerHolder<NewsItem> implements View.OnClickListener {
    @BindView(R.id.item_city_state_news_img)
    protected CustomEXImageView img;
    @BindView(R.id.item_city_state_news_title)
    protected CustomFontTextView title;
    @BindView(R.id.item_city_state_news_lable)
    protected CustomFontTextView lable;
    @BindView(R.id.item_city_state_news_time)
    protected CustomFontTextView time;
    private NewsItem newsItem;

    public CityStaNewsHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(NewsItem newsItem) {
        this.newsItem = newsItem;
        if (!TextUtils.isEmpty(newsItem.getNewsImage())) {
            GlideUtil.getGlideWithSmall169Def(context, newsItem.getNewsImage()).into(img);
        }
        if (!TextUtils.isEmpty(newsItem.getNewsTitle())) {
            title.setVisibility(View.VISIBLE);
            title.setText(newsItem.getNewsTitle());
        }
        if (!TextUtils.isEmpty(newsItem.getLable())) {
            lable.setVisibility(View.VISIBLE);
            lable.setText(newsItem.getLable());
        }
        if (!TextUtils.isEmpty(newsItem.getPubTime())) {
            time.setVisibility(View.VISIBLE);
            //时间显示格式 月-日 时:分
            time.setText(DateUtils.formatDateNoYear(DateUtils.getDataDate(newsItem),""));
        }

    }

    @Override
    public void onClick(View v) {
        if (internalClick != null) {
            itemView.setTag(R.id.adapter_item_data_key, newsItem);
            internalClick.onItemInternalClick(itemView, v, getAdapterPosition());
        }
    }
}
